package 
{
	import assets.constants.AssetClassNames;
	import flash.display.Bitmap;
	import flash.utils.Dictionary;
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;
	
	/**
	 * The assets class
	 * @author Epixcs
	 */
	
	public class Assets 
	{
		/* model:
		[Embed( source = "/../media/graphics/<name>.png" )]
		public static const BM_<name>:Class:
		
		[Embed( source="/../media/graphics/<name>.xml", mimeType = "application/octet-stream" )]
		public static const XML_<name>:Class;
		*/
		
		/**
		 * The splash screen background
		 */
		[Embed( source = "/../media/graphics/backgrounds/bg_splash.png" )]
		public static const BM_bgSplash:Class;
		
		/**
		 * The splash screen play button
		 */
		[Embed( source = "/../media/graphics/buttons/btn_play.png" )]
		public static const BM_btnPlay:Class;
		
		/**
		 * The splash screen about button
		 */
		[Embed( source = "/../media/graphics/buttons/btn_about.png" )]
		public static const BM_btnAbout:Class;
		
		/*************************************************************************/
		
		/**
		 * The game textures dictionnary
		 */
		public static var gameTextures:Dictionary 	= new Dictionary;
		
		/**
		 * The game atlases dictionnary
		 */
		public static var gameAtlases:Dictionary	= new Dictionary;
		
		/*************************************************************************/
		
		/**
		 * Get a texture by name
		 * @param	name The name of the texture we're looking for
		 * @return 	a Texture object
		 */
		public static function getTexture( name:String ):Texture
		{
			// check if the texture is in the dictionary
			if ( Assets.gameTextures[name] == undefined )
			{
				// create the texture bitmap from embedded images
				var bm:Bitmap = new Assets[AssetClassNames.PREFIX_TEXTURE + name]();
				
				// add it to the dictionary
				Assets.gameTextures[name] = Texture.fromBitmap( bm );
			}
			
			// return the texture
			return Assets.gameTextures[name];
		}
		
		/**
		 * Get an atlas by name
		 * @param	name The name of the atlas we're looking for
		 * @return 	a Texture Atlas object
		 */
		public static function getAtlas( name:String ):TextureAtlas
		{
			if ( Assets.gameAtlases[name] == undefined )
			{
				// create the texture atlas from embedded data
				var texture:Texture 		= Assets.getTexture( name );
				var xml:XML					= XML( new Assets[AssetClassNames.PREFIX_ATLAS_XML + name]() );
				Assets.gameAtlases[name]	= new TextureAtlas( texture, xml );
			}
			
			// return the atlas
			return Assets.gameAtlases[name];
		}
		
	}

}